<?php
	if (isset($_POST["level"])) {
		$lv = $_POST["level"];
		$url = "http://data2.yome.vn/api/get-picture?username=sunnet&password=sunnet&question_start=".$lv;
		$file_content = file_get_contents($url);
		$data = json_decode($file_content, true);

		if($data["success"]){
			$counter = 0;
			foreach ($data["picture_list"] as $value) {
				$value["answer"] = changeName($value["answer"]);
				if($counter > 0)
					echo '|'.$value["level"].'-'.$value["picture"].'-'.$value["answer"];
				else
					echo $value["level"].'-'.$value["picture"].'-'.$value["answer"];
				$counter++;
			}
		}else
			echo "0";
	}

	function changeName($str){

		    /*if(!$str) return false;
		    $unicode = array(
		        'a'=>array('á','à','ả','ã','ạ','ă','ắ','ặ','ằ','ẳ','ẵ','â','ấ','ầ','ẩ','ẫ','ậ'),
		        'A'=>array('Á','À','Ả','Ã','Ạ','Ă','Ắ','Ặ','Ằ','Ẳ','Ẵ','Â','Ấ','Ầ','Ẩ','Ẫ','Ậ'),
		        'd'=>array('đ'),
		        'D'=>array('Đ'),
		        'e'=>array('é','è','ẻ','ẽ','ẹ','ê','ế','ề','ể','ễ','ệ'),
		        'E'=>array('É','È','Ẻ','Ẽ','Ẹ','Ê','Ế','Ề','Ể','Ễ','Ệ'),
		        'i'=>array('í','ì','ỉ','ĩ','ị'),
		        'I'=>array('Í','Ì','Ỉ','Ĩ','Ị'),
		        'o'=>array('ó','ò','ỏ','õ','ọ','ô','ố','ồ','ổ','ỗ','ộ','ơ','ớ','ờ','ở','ỡ','ợ'),
		        'O'=>array('Ó','Ò','Ỏ','Õ','Ọ','Ô','Ố','Ồ','Ổ','Ỗ','Ộ','Ơ','Ớ','Ờ','Ở','Ỡ','Ợ'),
		        'u'=>array('ú','ù','ủ','ũ','ụ','ư','ứ','ừ','ử','ữ','ự'),
		        'U'=>array('Ú','Ù','Ủ','Ũ','Ụ','Ư','Ứ','Ừ','Ử','Ữ','Ự'),
		        'y'=>array('ý','ỳ','ỷ','ỹ','ỵ'),
		        'Y'=>array('Ý','Ỳ','Ỷ','Ỹ','Ỵ')
		    );
		    foreach($unicode as $nonUnicode=>$uni){
		        foreach($uni as $value)
		        $str = @str_replace($value,$nonUnicode,$str);
		    } */
		    return strtoupper($str);
	}  
?>
